<template>
  <div class="component__course_card" @click="toPath(detail.id)">
    <div :class="['course-box', bottomInline ? 'bottom' : '']">
      <div
        class="tags"
        v-if="
          !is_hidden_content &&
           !is_show_price &&
            !detail.isFree &&
            isMemberFree &&
            !detail.isDiscount
        "
      >
        <van-tag color="var(--theme-color)">会员限免</van-tag>
      </div>

      <div :class="['card_left', kl_md.KLGL == 1 ? 'gelin-card' : '']">
        <!-- 非折扣 -->
        <template v-if="!detail.isDiscount && !is_hidden_content">
          <van-tag class="card-tag" type="primary" v-if="detail.isLive"
            >直播</van-tag
          >
          <van-tag
            class="card-tag"
            type="primary"
            v-if="
              !is_show_price &&
                !detail.isLive &&
                detail.isFree &&
                type != 'bought'
            "
            >免费</van-tag
          >
        </template>
        <!-- 折扣 -->
        <template v-if="detail.isDiscount && !is_hidden_content&& !is_show_price">
          <van-tag class="card-tag" type="primary" v-if="!detail.isFree"
            >限时优惠</van-tag
          >
          <van-tag class="card-tag" type="primary" v-if="detail.isFree"
            >免费</van-tag
          >
        </template>
        <!-- 会员限免 -->
        <!-- <template v-if="!detail.isFree && isMemberFree && !detail.isDiscount">
          <van-tag class="card-tag" type="primary">会员限免</van-tag>
        </template> -->
        <img class="icon_path" v-lazy="detail.iconPath" :key="detail.iconPath" />
      </div>
      <div :class="['card_right', kl_md.KLGL == 1 ? 'gelin-card' : '']">
        <div class="card-title">{{ detail.courseName }}</div>
        <div class="card_label" v-if="type != 'bought'">
          <template v-if="detail.label">
            <span
              v-for="(item, index) in JSON.parse(detail.label)"
              :key="index"
              style="margin-right:.1rem;"
              >#{{ item }}</span
            >
          </template>
        </div>
        <div class="card-info" v-if="type != 'bought'">
          <div class="card-info-left">
            <img src="/img/mobile/live_menus_heat.png" alt="" />
            <span>{{ detail.studentSum }}</span>
            <!-- <span style="margin:0 .1rem;">|</span>
            <span>共{{ detail.chapterNum }}课时</span> -->
          </div>
          <div class="card-info-right">
            <template
              v-if="!is_show_price && !is_hidden_content && detail.isDiscount && !detail.isFree"
            >
              <div>
                <span class="oldprice"
                  ><span class="coursedot">&yen;</span>{{ detail.price }}</span
                >
                <span class="price"
                  ><span class="coursedot">&yen;</span
                  >{{ detail.discountPrice }}</span
                >
              </div>
            </template>
            <template v-else>
              <div v-if="!is_show_price && !is_hidden_content">
                <span class="price" v-if="detail.isFree">免费</span>
                <span class="price" v-if="!detail.isFree && isMemberFree"
                  ><span class="coursedot">&yen;</span>0.00</span
                >
                <span
                  class="price"
                  v-if="!isMemberFree && !detail.isFree && !is_member"
                  ><span class="coursedot">&yen;</span>{{ detail.price }}</span
                >
                <span
                  class="price"
                  v-if="
                    kl_md.KLHY == 1 &&
                      !isMemberFree &&
                      !detail.isFree &&
                      is_member
                  "
                >
                  <span v-if="user_member && user_member.memberLevel === 0"
                    >会员价￥{{
                      Number(detail.smallMemberPrice).toFixed(2)
                    }}</span
                  >
                  <span v-if="user_member && user_member.memberLevel === 1"
                    >会员价￥{{
                      Number(detail.middleMemberPrice).toFixed(2)
                    }}</span
                  >
                  <span v-if="user_member && user_member.memberLevel === 2"
                    >会员价￥{{
                      Number(detail.highMemberPrice).toFixed(2)
                    }}</span
                  >
                </span>
              </div>
            </template>
          </div>
        </div>
        <div class="card-comment" v-if="type === 'bought'">
          <van-button type="primary" round plain size="small" v-if="detail.isComment != 1 && kl_md.KLKCPJ == 1" @click.stop="toComment(detail.id)">评价课程</van-button>
        </div>
        <div
          class="card-info"
          v-if="type === 'bought'"
          style="margin:10px 0;display:flex;"
        >
          <van-progress
            style="width:80%"
            :percentage="Math.ceil(detail.schedule * 100)"
            color="var(--theme-color)"
            :show-pivot="false"
          /><span style="margin-left:10px;line-height: 0.2;"
            >{{ Math.ceil(detail.schedule * 100) }}%</span
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  props: [
    "detail",
    "type",
    "memberDiscount",
    "user_member",
    "is_member",
    "bottomInline"
  ],
  components: {},
  data() {
    return {};
  },
  computed: {
    ...mapState({
      is_ios(state) {
        return state.is_ios;
      },
      is_in_wechat(state) {
        return state.is_in_wechat;
      },
      member_discount(state) {
        return state.member_discount;
      },
      is_hidden_content(state) {
        return state.is_hidden_content;
      },
      kl_md(state) {
        return state.kl_md;
      },
      is_wechat_ios_limit(state) {
        return state.is_wechat_ios_limit;
      }
    }),

    isMemberFree() {
      // console.log("member_discount",this.memberDiscount)
      if (this.memberDiscount && JSON.stringify(this.memberDiscount) !== "{}") {
        if (
          this.memberDiscount.majorIds.includes(this.detail.majorId) ||
          this.memberDiscount.courseIds.includes(this.detail.id)
        ) {
          return true;
        } else {
          return false;
        }
      }
    },
    is_show_price() {
      if (this.is_wechat_ios_limit) {
        return this.is_ios && this.is_in_wechat;
      } else {
        return false;
      }
    }
  },
  watch: {},
  methods: {
    // toPath(detail) {
    //   console.log("进来了",detail)
    //   if (this.type == "bought") {
    //     this.$router.push({
    //       path: "/m/course-detail",
    //       query: {
    //         id: detail.courseId
    //       }
    //     });
    //   } else {
    //     this.$router.push({
    //       path: "/m/course-detail",
    //       query: {
    //         id: detail.id
    //       }
    //     });
    //   }
    // }
    toComment(id) {
      this.$router.push({
        path: "/m/comment",
        query: {
          courseId:id
        }
      });
    },
    toPath(id) {
      this.$router.push({
        path: "/m/course-detail",
        query: {
          id
        }
      });
    }
  },
  created() {
    console.log(this.detail);
  },
  mounted() {}
};
</script>

<style lang="scss" scoped>
.component__course_card {
  width: 6.8rem;
  box-sizing: content-box;
  padding: 0 0.2rem;
  .course-box {
    position: relative;
    display: flex;
    align-items: center;
    overflow: hidden;
    width: 100%;
    height: 2.3rem;
    .card_left {
      width: 2.72rem;
      border-radius: 0.04rem;
      overflow: hidden;
      position: relative;
      .card-tag {
        position: absolute;
        top: 0.1rem;
        left: 0;
        font-size: 0.16rem;
      }
      img {
        width: 100%;
        // width: 3.75rem;
        height: 1.8rem;
        display: block;
        background: var(--theme-color);
      }
    }
    .card_left.gelin-card {
      width: 1.35338rem;
    }
    .card_right {
      width: 60%;
      box-sizing: border-box;
      // padding: .1rem .2rem;
      padding: 0.1rem 0rem 0.1rem 0.2rem;
      .card-title {
        // font-size: .3rem;
        // font-size: .24rem;
        font-size: 0.2688rem;
        height: 0.8rem;
        line-height: 0.4rem;
        color: #494a4d;
        font-weight: bold;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        overflow: hidden;
        text-overflow: ellipsis;
        -webkit-box-orient: vertical;
      }
      .card_label {
        font-size: 0.26rem;
        line-height: 0.5rem;
        height: 0.5rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .card-info {
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 0.24rem;
        .card-info-left {
          display: flex;
          align-items: center;
          color: #adafb3;
          img {
            width: 0.4rem;
            height: 0.4rem;
            display: block;
          }
        }
        .card-info-right {
          // font-size: .34rem;
          font-family: "微软雅黑", arial, "\5b8b\4f53";
          color: var(--theme-color);
          // font-family: -apple-system,BlinkMacSystemFont,Microsoft YaHei UI,Microsoft YaHei,Roboto,Hiragino Sans GB,Source Han Sans CN,Fira Sans,Droid Sans,Helvetica Neue,arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
          .coursedot {
            // font-size: .26rem;
            margin-right: 0.06rem;
          }
          .price {
          }
          .oldprice {
            color: #666;
            position: relative;
          }
          .oldprice::before {
            content: "";
            display: block;
            position: absolute;
            left: -5%;
            top: 50%;
            transform: translateY(-50%);
            width: 110%;
            height: 0.02rem;
            background: #666;
          }
        }
      }
      .card-comment{
        text-align: right;
        margin: .1rem 0;
        height: .4224rem;
      }
    }
    .card_right.gelin-card {
      width: 5.4rem;
    }
    .tags {
      position: absolute;
      right: 0;
      top: 0;
    }
    .card-img {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 2.52rem;
      height: 1.73rem;
      margin-right: 0.2rem;
      overflow: hidden;
      border-radius: 0.08rem;
      background-color: #e5e5e5;
      img {
        width: 100%;
        height: auto;
      }
    }
    .card-content {
      flex: 1;
      // display: flex;
      // flex-direction: column;
      overflow: hidden;
      .card-title {
        // margin-top: 0.1rem;
        margin-top: 0.3rem;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
        min-height: 0.7rem;
        font-size: 0.26rem;
        color: #010101;
        line-height: 0.35rem;
      }
      .line {
        &::before {
          content: "";
          width: 0.02rem;
          height: 0.2rem;
          background-color: #ddd;
          display: inline-block;
          vertical-align: -0.02rem;
          margin: 0 0.1rem 0 0.03rem;
        }
      }
      .card-info {
        margin-top: 0.15rem;
        font-size: 0.21rem;
        line-height: 0.21rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        color: #101010;
        i {
          vertical-align: text-bottom;
          margin-right: 0.05rem;
          font-size: 0.3rem;
          color: var(--theme-color);
        }
      }
      .card-info-line {
        margin-top: 0.2rem;
        display: flex;
        .line-item {
          display: flex;
          align-items: center;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          &:last-child {
            flex: 1;
          }
        }
        .line-item + .line-item {
          margin-left: 0.1rem;
        }
        .price {
          color: #f0423d;
          font-size: 0.26rem;
          justify-content: flex-end;
          font-weight: 700;
          .price-market {
            margin-right: 0.08rem;
            color: #666;
            font-weight: 400;
            font-size: 0.18rem;
            text-decoration: line-through;
            text-align: right;
            vertical-align: text-bottom;
            line-height: normal;
          }
        }
        .price-free {
          color: #4fc08d;
          font-weight: 400;
        }
      }
      .card-info2 {
        flex: 1;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
        font-size: 0.22rem;
        line-height: 0.3rem;
        max-height: 0.6rem;
        color: #666;
      }
    }
  }
  .course-box.bottom {
    border-bottom: solid 0.02rem #ededf1;
  }
}
// .component__course_card + .component__course_card {
//   margin-top: 0.1rem;
// }
</style>
<style lang="scss">
.component__course_card {
  .card-img {
    position: relative;
    .card-tag {
      position: absolute;
      top: 0.1rem;
      left: 0;
      font-size: 0.16rem;
    }
  }
}
</style>
